/***************************init***************/

function queryLeave_leave(page){
	sys_loading();
	var parm = $('#queryLeaveForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('leave-query');
	sys_record_parm('leave',parm);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#leaveResultList').html(result);
		}
	});
}


function edit_leave(code) {
	var url = create_url('leave-edit');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm});
}

function aidExecuteLeave_leave(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				sys_msg('操作成功!');
				queryLeaveApply_leave();
			} else {
				sys_warning('操作失败', '操作失败，请刷新页面再次尝试，如果问题依然存在，请联系管理员!');
			}
		}
	});
}

function queryLeaveApply_leave(page){
	sys_loading();
	var parm = $('#queryLeaveApplyForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('leaveApply-query');
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#leaveApplyResultList').html(result);
		}
	});
}


function editLeaveApply_leave(code) {
	var parm = {'code':code};
	var url = create_url('leave-editApply');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm});
}

function editAgree_leave(code) {
	var parm = {'code':code};
	var url = create_url("leave-editAgree");
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'500px', open:true});
}


function shield_leave(code) {
	$.Zebra_Dialog('确认要屏蔽此次 请假吗？',{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
	           {caption:'屏蔽',callback:function() {
	        	   var url = create_url('leaveApply-shield');
	   	    	aidExecuteLeave_leave(code, url);
	    		}},
	           {caption:'取消',callback:function(){}
	    	}]
	});
}

function unshield_leave(code) {
	$.Zebra_Dialog('确认要解除屏蔽状态吗？',{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
	           {caption:'解除',callback:function() {
	        	   var url = create_url('leaveApply-unshield');
	   	    	aidExecuteLeave_leave(code, url);
	    		}},
	           {caption:'取消',callback:function(){}
	    	}]
	});
}
/*******************************edit***********************/
function saveLeave_leave() {
	var parm = $('#editLeaveForm').serialize();
	var url = create_url('leave-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功');
				sys_load_handle('leave');
			}else if(result == 'not_update'){
				sys_msg('申请同意后不能修改');
				sys_load_handle('leave');
		  	}else {
				sys_msg('操作失败');
			}
		}
	});
}

function saveLeaveApply_leave() {
	var parm = $('#editLeaveApplyForm').serialize();
	var url = create_url('leaveApply-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功');
				sys_load_handle('leaveApply');
			}else if(result == 'null_time') {
				sys_msg('请假时间不能为空');
			}else if(result == 'null_reason') {
				sys_msg('请假原因不能为空');
			}else if(result == 'not_update'){
				sys_msg('申请同意后不能修改');
				sys_load_handle('leaveApply');
		  	}else if(result == 'not_find'){
		  		sys_msg('没有审核流程，不能申请请假，  请及时添加审核流程!');
		  	}else {
		  		sys_msg('操作失败');
			}
		}
	});
}

function saveLeaveAgree_leave() {
	var parm = $('#editLeaveAgreeForm').serialize();
	var url = create_url('leave-saveAgree');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				$.fn.colorbox.close();
				sys_msg('操作成功');
				sys_load_handle('leave');
			}else if(result == 'pwd_error'){
				$.fn.colorbox.close();
				sys_msg('同意人密码错误', '警告');
			}else {
				$.fn.colorbox.close();
				sys_msg('操作失败', '警告');
			}
		}
	});
}
function check_leave() {
	var remark = $('#remark').val();
	if (remark == null || remark == ''){
		$('#remark').css('border-color','red');
	}
}
//点击查看完以后,修改确认状态
function updateDesignate2_leave(code) {
	var remark = $('#remark').val();
	if (remark == null || remark == ''){
		sys_msg('亲，要说明驳回原因的哦！');
		return false;
	}
	var parm =  {'code':code, 'remark': remark};
	var url = create_url('leave-updateDesignate2');
	$.ajax({type:'POST',url:url, data:parm,
		success:function (result) {
				sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功!');
				sys_load_handle('leave');
			} else if (result == 'exists') {
				sys_msg('对不起！已经审核过了！');
			} else if (result == 'error') {
				sys_msg('对不起! 你没有权限');
			} else if (result == 'parameter_error') {
				sys_msg('对不起! 驳回原因不能为空！');
			} else {
				sys_msg('操作失败!');
			}
		}
	});
}